package moodish.dummy;


import java.util.LinkedList;

import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;


public class MyTableModel extends AbstractTableModel {

	private LinkedList<UserDummy> users = new LinkedList<UserDummy>();
	
	
	@Override
	public int getColumnCount() {
		return 2;
	}

	@Override
	public int getRowCount() {
		return users.size();
	}

	@Override
	public String getColumnName(int column) {
		switch(column){
		case 0:
			return "Nome";
		case 1:
			return "Mood";
		
		}
		return null;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		UserDummy u = users.get(rowIndex);
		switch(columnIndex){
		case 0:
			return u.getName();
		case 1:
			return u.getMood();
		
		}
		return null;
	}

	public void addUser(UserDummy user) {
		users.add(user);
		fireTableDataChanged();
	}
	
	public void removeUser(UserDummy user) {
		users.remove(user);
		fireTableDataChanged();
	}
	
	public void clearTable(){
		users.clear();
	}

	public UserDummy getUser(int index){
		return users.get(index);	
	}
	
	



}
